//
//  RequestTableViewCell.m
//  project
//
//  Created by 黄建华 on 2018/8/15.
//  Copyright © 2018年 黄建华. All rights reserved.
//

#import "RequestTableViewCell.h"

@implementation RequestTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    
    return self;
}

- (void)createView {
    _headImage = [[UIImageView alloc]init];
    [self addSubview:_headImage];
    
    _nickLabel = [[UILabel alloc] init];
    [self addSubview:_nickLabel];
    
    _infoLabel = [[UILabel alloc] init];
    [self addSubview:_infoLabel];
    
    _line = [[UIView alloc] init];
    [self addSubview:_line];
    
    _finishButton = [[UILabel alloc] init];
    [self addSubview:_finishButton];
    
    _invTimeLabel = [[UILabel alloc] init];
    [self addSubview:_invTimeLabel];
    
    _okButton = [[UIButton alloc] init];
    [self addSubview:_okButton];
    
    _cancelButton = [[UIButton alloc] init];
    [self addSubview:_cancelButton];
}

- (void)updateCellWithModel:(FriednInviterModel *)model {
    _headImage.frame               = SNFRAME(20, 5, 50, 50);
    _headImage.layer.masksToBounds = YES;
    _headImage.layer.cornerRadius  = _headImage.width /2.0;
    [_headImage sd_setImageWithURL:[NSURL URLWithString:model.imagePathUrlString] placeholderImage:[UIImage imageNamed:@"loginhead"]];
    
    _nickLabel.text      = [NSString stringWithFormat:@"%@", model.showNickName];
    _nickLabel.textColor = SNCOLORBLACK;
    _nickLabel.frame     = SNFRAME(_headImage.right + 15, 7, 180, 25);
    _nickLabel.font      = SNFONT(15.0);
    _nickLabel.adjustsFontSizeToFitWidth = YES;
    _nickLabel.minimumScaleFactor = 0.5;
    
    _infoLabel.text      = SN_Text(@"请求添加你为好友");
    _infoLabel.textColor = SNCOLORGRAY;
    _infoLabel.frame     = SNFRAME(_headImage.right + 15, _nickLabel.bottom + 3, 200, 20);
    _infoLabel.font      = SNFONT(11.0);
    _infoLabel.adjustsFontSizeToFitWidth = YES;
    _infoLabel.minimumScaleFactor = 0.5;
    
    _line.backgroundColor = SNCOLORGRAYLINE;
    _line.frame           = SNFRAME(0, 59, screenWidth, 1);
    
    _okButton.frame               = SNFRAME(screenWidth - 110 -30, 7, 55, 30);
    _okButton.titleLabel.font     = SNSFONT(12.0);
    _okButton.layer.cornerRadius  = 4.0;
    _okButton.layer.masksToBounds = YES;
    [_okButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_okButton setTitleColor:SNCOLORGRAY forState:UIControlStateHighlighted];
    
    _cancelButton.titleLabel.font     = SNSFONT(12.0);
    _cancelButton.layer.cornerRadius  = 4.0;
    _cancelButton.layer.masksToBounds = YES;
    _cancelButton.frame               = SNFRAME(_okButton.right +15, 7, 55, 30);
    [_cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_cancelButton setTitleColor:SNCOLORGRAY forState:UIControlStateHighlighted];
    
    _finishButton.font          = SNSFONT(14.0);
    _finishButton.textAlignment = NSTextAlignmentRight;
    _finishButton.frame         = SNFRAME(screenWidth - 115, 5, 100, 25);
    _finishButton.textColor     = SNCOLORGRAY;
    
    NSArray *timeA = [model.lastInvTime componentsSeparatedByString:@" "];
    NSString *dateTime = [timeA firstObject];
    NSString *timeShow = [timeA lastObject];
    NSString *todayString = [[NSDate date]dateToDayString];
    if ([todayString isEqualToString:dateTime]) {
       _invTimeLabel.text          = timeShow;
    }
    else{
        _invTimeLabel.text         = dateTime;
    }
    
    _invTimeLabel.textAlignment = NSTextAlignmentRight;
    _invTimeLabel.textColor     = SNCOLORGRAY;
    _invTimeLabel.frame         = SNFRAME(screenWidth - 165, _infoLabel.top, 150, 20);
    _invTimeLabel.font          = SNFONT(11.0);
    
    if (model.state == 1) {
        [_okButton setTitle:SN_Text(@"同意") forState:UIControlStateNormal];
        [_cancelButton setTitle:SN_Text(@"拒绝") forState:UIControlStateNormal];
        _okButton.backgroundColor     = SNCOLORBLACK;
        _cancelButton.backgroundColor = SNCOLORBLACK;
        _okButton.hidden              = NO;
        _cancelButton.hidden          = NO;
        _finishButton.hidden          = YES;
    }
    if (model.state == 2 || model.state == 3) {
        _okButton.hidden     = YES;
        _cancelButton.hidden = YES;
        _finishButton.hidden = NO;
    }
    
    if (model.state == 2) {
        _finishButton.text = SN_Text(@"已同意");
    }
    if (model.state == 3) {
        _finishButton.text = SN_Text(@"已拒绝");
    }
    
    _okButton.titleLabel.adjustsFontSizeToFitWidth = YES;
    _okButton.titleLabel.minimumScaleFactor = 0.5;
    
    _cancelButton.titleLabel.adjustsFontSizeToFitWidth = YES;
    _cancelButton.titleLabel.minimumScaleFactor = 0.5;
    
    _invTimeLabel.adjustsFontSizeToFitWidth = YES;
    _invTimeLabel.minimumScaleFactor = 0.5;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
